extends "../ib.gd"
var cnt
var cnt2
var cell
func init():
	.init()
	name = "核心钥匙"
	resetdata()
	att.maxHp = 188
	att.atk = 13
	info = "核心激发：[近战（攻击范围1-2）]吸血+33%，护盾+10%生命上限，持续3秒，之后减伤-10%，攻击-15%，持续2秒\n[远程（攻击距离3以上）]吸血+15%，攻速+66%，持续3秒，之后减伤-5%，攻速-50%，持续2秒[cd:7秒]\n"
#根据等级增加属性
func addatt():
	att.maxHp += 200
	att.atk += 23
	att.cri = 0.05
#链接信号
func _connect():
	._connect()
	yield(sys.get_tree().create_timer(0.05),"timeout")
	if !masCha:return
	sys.main.connect("onBattleStart",self,"resetcnt")
	if !masCha.is_connected("onAddItem",self,"check"):
		masCha.connect("onAddItem",self,"check")
#检查是否只有一双鞋
func check(item):
	yield(sys.get_tree().create_timer(0.02),"timeout")
	if item.id.find("key") != -1 && item != self:
		masCha.delItem(item)
		sys.newBaseMsg("提示","一个角色只能装备一把钥匙")
#重置技能计数
func resetcnt():
	cnt = 0
#进化装备
func upgradeself(item):
	var chose = item.chose
	var c = str(chose)
	var upid = "_Hide_MAX"
	upid = self.id + upid
	self.switchchose(chose)
	var nitem = sys.newItem(upid)
	sys.main.player.addItem(nitem)
	masCha.disconnect("onAddItem",self,"check")
	masCha.addItem(nitem)
	nitem.inheritatt(nitem,self)
	nitem.addatt()
	nitem.upinfo()
	self.delself()

#技能计时
func _upS():
	._upS()
	cnt += 1
	if cnt == 7:
		cnt = 0
		masCha.addBuff(hxjf.new(1,masCha.att.atkRan))
		if self.id != "i_TD_key":
			var chas = masCha.getAllChas(1)
			for i in chas:
				var x = abs(i.cell.x - masCha.cell.x)
				var y = abs(i.cell.y - masCha.cell.y)
				if x*x + y*y <= 4:
					i.addBuff(ctrl.b_xuanyun.new(1))
					masCha.hurtChara(i,masCha.att.maxHp * 0.05,Chara.HurtType.REAL,Chara.AtkType.SKILL)

class hxjf:
	extends Buff
	var canremove:bool = false
	var r
	func _init(lv,r):
		attInit()
		life = 5.0
		id = "hxjf"
		self.r = r
	func _connect():
		att.suck = 0.15
		if r  < 3:
			att.suck += 0.18
			masCha.changeShield(masCha.att.maxHp * 0.1)
		else:
			att.spd = 0.66

	func _upS():
		if life <= 2:
			att.suck = 0
			att.spd = 0
			att.defR = -0.05
			if r < 3:
				att.defR += -0.05
				att.atkL = -0.15
			else:
				att.spd = -0.5